<?php

namespace App\Services;

use Illuminate\Support\Facades\DB;

class MailConfigService
{

    public static function getField($key)
    {
        $config = DB::table('mail_config')->first();
        if ($config) {
            return $config->$key;
        }
        return null;
    }

    public static function getHost()
    {
        return self::getField('host');
    }

    public static function getPort()
    {
        return self::getField('port');
    }

    public static function getUsername()
    {
        return self::getField('username');
    }

    public static function getPassword()
    {
        return self::getField('password');
    }

    public static function getFromAddress()
    {
        return self::getField('from_address');
    }

    public static function getFromName()
    {
        return self::getField('from_name');
    }

    public static function getEncryption()
    {
        $encrypt = self::getField('encryption');
        if (empty($encrypt)) {
            return null;
        }
        return $encrypt == 1 ? 'tls' : 'ssl';
    }
}
